package com.example;
import java.io.*;
import java.util.Random;

public class MathProblemGenerator {
    public static void generateProblems(String fileName) {
        try (PrintWriter writer = new PrintWriter(new FileWriter(fileName))) {
            writer.println("题号,算式,答案");
            Random random = new Random();
            
            for (int i = 1; i <= 50; i++) {
                int num1 = random.nextInt(100);
                int num2 = random.nextInt(100);
                boolean isAddition = random.nextBoolean();
                
                String operator = isAddition ? "+" : "-";
                int answer;
                
                // 确保减法结果为正数
                if (!isAddition && num1 < num2) {
                    int temp = num1;
                    num1 = num2;
                    num2 = temp;
                }
                
                answer = isAddition ? num1 + num2 : num1 - num2;
                String problem = num1 + " " + operator + " " + num2 + " = ";
                
                writer.println(i + "," + problem + "," + answer);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} 